package com.mutual.reins.verify.service.impl;

import com.mutual.reins.interf.entity.ReinsOverPolicyDto;
import com.mutual.reins.verify.service.IVerifyInerfService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
/**
 * 实现校验传值数据接口
 *
 * @author panchen
 * @since 2021-04-26
 */
@Service
@Transactional(rollbackFor = Exception.class)
@Slf4j
public class VerifyInerfServiceImpl implements IVerifyInerfService {

    /**
     * 校验ReinsOverPolicyDto对象是否为空
     *
     * @param reinsOverPolicyDto 保单审核通过接口数据传输实体
     * @return 校验结果
     */
    @Override
    public String checkHttpServiceUndwrtData(ReinsOverPolicyDto reinsOverPolicyDto) {
        List<String> failReasonList;
        StringBuilder failReasonBuilder = new StringBuilder();
        //字段非空校验
        failReasonList = this.checkNoNullPolicyUndwrtData(reinsOverPolicyDto);
        if(failReasonList!=null && !failReasonList.isEmpty()){
            for(String failReasonUnit : failReasonList){
                failReasonBuilder.append(failReasonUnit);
            }
            return failReasonBuilder.toString();
        }
        return "";
    }
    public List<String> checkNoNullPolicyUndwrtData(ReinsOverPolicyDto reinsOverPolicyDto) {
        List<String> errorInfo = new ArrayList<>();
        if(reinsOverPolicyDto.getCerTiType()==null||"".equals(reinsOverPolicyDto.getCerTiType())){
            errorInfo.add("ReinsOverPolicyDto对象CerTiType不能为空");
        }
        if(reinsOverPolicyDto.getPolicyNo()==null||"".equals(reinsOverPolicyDto.getPolicyNo())){
            errorInfo.add("ReinsOverPolicyDto对象PolicyNo不能为空");
        }
        if(reinsOverPolicyDto.getProposalNo()==null||"".equals(reinsOverPolicyDto.getProposalNo())){
            errorInfo.add("ReinsOverPolicyDto对象ProposalNo不能为空");
        }
        if(reinsOverPolicyDto.getUnderwriteCode()==null||"".equals(reinsOverPolicyDto.getUnderwriteCode())){
            errorInfo.add("ReinsOverPolicyDto对象UnderwriteCode不能为空");
        }

        if(reinsOverPolicyDto.getUnderWriteEndDateStr()==null||"".equals(reinsOverPolicyDto.getUnderWriteEndDateStr())){
            errorInfo.add("ReinsOverPolicyDto对象UnderWriteEndDateStr不能为空");
        }
        if(reinsOverPolicyDto.getType()==null||"".equals(reinsOverPolicyDto.getType())){
            errorInfo.add("ReinsOverPolicyDto对象Type不能为空");
        }
        return errorInfo;
    }
}
